package com.example.zaq.rest;

import com.example.zaq.dao.AspKindModelDao;
import com.example.zaq.dao.AspModelDao;
import com.example.zaq.model.AspKindModel;
import com.example.zaq.model.AspModel;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 20210607  zaq  快速添加模块
 * @author 阿恩
 * @date 2021/6/716:09
 */
@RestController
@RequestMapping("/quick")
public class AspModelRest {
    @Autowired
    SqlSessionFactory factory;

    /**
     * 查询操作日志
     * http://localhost:9090/quick/insert
     * @param body
     * @return
     */
    @PostMapping("insert")
    @ResponseBody
    public AspModel getAll(@RequestBody AspModel body){
        AspModel aspModel=null;
        try{
            System.out.println("获得值:"+body);
            SqlSession sess=factory.openSession();
            AspModelDao aspKindModelDao=sess.getMapper(AspModelDao.class);
            aspModel=aspKindModelDao.quickAdd(body);
            sess.close();
            System.out.println(aspModel);
            System.out.println("快速添加结束");
            return aspModel;
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            return aspModel;
        }
    }

    /**
     * 查询操作日志
     * http://localhost:9090/quick/getAll
     * @param body
     * @return
     */
    @PostMapping("getAll")
    @ResponseBody
    public List<AspKindModel> getAll(@RequestBody AspKindModel body){
        List<AspKindModel> aspKindModel=null;
        try{
            System.out.println("获得值:"+body);
            SqlSession sess=factory.openSession();
            AspKindModelDao aspKindModelDao=sess.getMapper(AspKindModelDao.class);
            aspKindModel=aspKindModelDao.select(body);
            sess.close();
            System.out.println(aspKindModel);
            System.out.println("查询模板结束");
            return aspKindModel;
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            return aspKindModel;
        }
    }
}
